home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byte1286.arc
/
ENNS.ARC
/
CURVTEST.BAS
< prev
next >
Wrap
BASIC Source File
|
1986-07-07
|
13KB
|
303 lines
1 ' ╔══════════════╦═════════════════════════╦════════════════════════╗
2 ' ║ CurvTest ║ 0277 Lines ║ Steve Enns Feb.21 1985 ║
3 ' ║ Version 1.1 ║ 11136 Bytes ║ Com. Feb.21 1985 ║
4 ' ╚══════════════╩═════════════════════════╩════════════════════════╝
5 '
10 '------------ Entry ---------------------------------------------------------
11 '
12 '----- Versions of BASIC for PC's other then the TI PC will likely require
13 '----- that this program initialize the graphics screen. The resolution
14 '----- of the graphics screen is given in lines 70 and 80. Line 80 contains
15 '----- the maximum x and y coordinates. The fourth place in a COLOR state-
16 '----- ment is the character attribute. (flashing, reverse video, etc.)
17 '----- Lines 4030 to 4050 draw and store a cross-hair cursor. Different
18 '----- screen resolutions may require a larger or smaller cursor. GSX and
19 '----- GSY determine how far the cursor will move on a shifted-arrow key.
20 '----- Both graphics and text on the same screen are required.
29 '
30 '----------- Initialize storage and variables -------------------------------
40 '
50 DEFINT X,Y
60 DIM XC(300),YC(300),X(5000),Y(5000) '----- Ctrl and curve points
70 XVI=0:YVI=0 '----- Upper left of Gr. screen
80 X1VI=719:Y1VI=299 '----- Lower Right of Gr. screen
90 GSX=30:GSY=20 '----- See GRCURSOR.SUB
100 GRIDIS=1 '----- See GRCURSOR.SUB
110 I=1 '----- Count of ctrl points
120 NBS=.05 '----- Increment (Curv.SUB's)
130 QBS=2:QBZ=4 '----- Colors for curves
140 '
150 '---------- Clear the screen -----------------------------------------------
160 '
170 CLS:KEY OFF:COLOR 3,,,0:LOCATE ,,0
180 '
190 '---------- Initialize function keys ---------------------------------------
200 '
210 KEY 1,"POINT ":ON KEY(1) GOSUB 600:KEY(1) ON
220 KEY 2,"SPLINE":ON KEY(2) GOSUB 770:KEY(2) ON
230 KEY 3,"BEZIER":ON KEY(3) GOSUB 850:KEY(3) ON
240 KEY 4,"EPOINT":ON KEY(4) GOSUB 690:KEY(4) ON
250 KEY 5,"ERASE ":ON KEY(5) GOSUB 940:KEY(5) ON
252 KEY 6,"EXIT ":ON KEY(6) GOSUB 996:KEY(6) ON
260 '
270 KEY ON
280 LOCATE 25,48:PRINT STRING$(32,32)
281 '
282 '---------- Title ----------------------------------------------------------
283 '
290 COLOR 7,,,0:LOCATE 1,1
291 PRINT"╔══════════╗"
293 PRINT"║ CURVTEST ║"
294 PRINT"╚══════════╝"
297 '
298 '---------- Main program ---------------------------------------------------
299 '
300 GOSUB 4040 '----- Init. (GRCURSOR.SUB)
310 GOSUB 3852 '----- Enter crosshair loop
320 '
330 '---------- Application specific subroutines -------------------------------
340 '
350 '---------- Update cursor coordinates --------------------------------------
360 '
370 COLOR 7,,,0:LOCATE 25,50
372 PRINT"Cursor: x=";XPOS;" y=";YPOS;
380 RETURN
450 '
460 '---------- Erase message --------------------------------------------------
470 '
480 COLOR 3,,,0:LOCATE 23,70
490 PRINT" ";
500 RETURN
510 '
520 '---------- Initialize control points for curves ---------------------------
530 '
540 XNC=1:XNB=I-1:I2=I:I=1 '----- Init. ctrl point position
542 COLOR 7,,,16+64:LOCATE 23,70
544 PRINT"WORKING"; '----- Print working message
550 RETURN
560 '
570 '---------- Function key interrupt vectors ---------------------------------
580 '
590 '---------- Get control points - (POINT) -----------------------------------
600 '
610 XC(I)=XPOS:YC(I)=YPOS
620 GOSUB 3930
630 PSET(XC(I),YC(I)),7 '----- Set pixel (xc(i),yc(i)),
640 GOSUB 3930 'with color 7
650 I=I+1
660 RETURN
670 '
680 '---------- Erase control points - (EPOINT) --------------------------------
690 '
700 FOR IC=1 TO I2
710 IF POINT(XC(IC),YC(IC))=QBS OR POINT(XC(IC),YC(IC))=QBZ THEN 730
720 PSET(XC(IC),YC(IC)),0 '----- Check for pixels, else
730 NEXT 'erase the pixel, color 0
740 RETURN
750 '
760 '---------- Put B-spline - (SPLINE) ----------------------------------------
770 '
780 GOSUB 540 '----- Init. curve ctrl points
800 GOSUB 16880 '----- Calc. and draw spline
810 GOSUB 480 '----- Erase message
820 RETURN
830 '
840 '---------- Put Bezier curve - (BEZIER) ------------------------------------
850 '
860 GOSUB 540 '----- Init. curve ctrl points
880 GOSUB 16990 '----- Calc. and draw Bez. curve
890 GOSUB 480 '----- Erase message
900 RETURN
910 '
920 '---------- Clear screen - (CLEAR) -----------------------------------------
930 '
940 GOSUB 3930
950 CLS 1 '----- Clear graphic and text
970 GOSUB 3930
980 GOSUB 370
990 RETURN
992 '
993 '---------- Leave program - (EXIT) -----------------------------------------
994 '
996 GOSUB 9821 '----- Replace key definitions
997 COLOR 3,,,0:CLS
998 END
1000 '
1010 '--------- General subroutines --------------------------------------------
1020 '
3780 ' Grcursor.SUB (Altered) Steve Enns Dec.26 1983
3790 '
3800 ' Calling program must execute a GOSUB 4040 to init. cursor
3810 ' Clears screen area descibed below
3820 ' XVI,YVI,X1VI,Y1VI is the viewport
3830 ' GRIDIS is 1 for no grid displayed
3840 ' GSX,GSY are the grid increments
3850 '
3852 GOSUB 4000
3854 GOSUB 4872
3858 IF GRIDIS THEN 3870
3860 X=XVI:Y=YVI:X1=X1VI:Y1=Y1VI:XS=GSX:YS=GSY:Q=1
3861 GOSUB 8340
3870 XCEN=XVI+.5*(X1VI-XVI):YCEN=YVI+.5*(Y1VI-YVI)
3871 XPOS=XCEN:YPOS=YCEN
3872 GOSUB 3950
3879 Q9$=INKEY$
3880 IF Q9$="" THEN 3879
3882 GOSUB 3930
3883 IF Q9$=LQ$ THEN XPOS=XPOS-1:GOTO 3950
3884 IF Q9$=RQ$ THEN XPOS=XPOS+1:GOTO 3950
3885 IF Q9$=DQ$ THEN YPOS=YPOS+1:GOTO 3950
3886 IF Q9$=UQ$ THEN YPOS=YPOS-1:GOTO 3950
3888 IF Q9$=HQ$ THEN MODE$="set":GOTO 3950
3890 IF Q9$=SRQ$ THEN XPOS=XPOS+GSX:GOTO 3950
3892 IF Q9$=SLQ$ THEN XPOS=XPOS-GSX:GOTO 3950
3894 IF Q9$=SDQ$ THEN YPOS=YPOS+GSY:GOTO 3950
3896 IF Q9$=SUQ$ THEN YPOS=YPOS-GSY:GOTO 3950
3900 IF Q9$=SHQ$ THEN XPOS=XCEN:YPOS=YCEN:GOTO 3950 ELSE 3950
3920 ' Erase cursor
3930 PUT(XC,YC),CUR '----- Put image CUR at XC,YC
3932 RETURN
3940 ' Put cursor
3950 GOSUB 3970
3951 GOSUB 370
3952 XC=XPOS-15:YC=YPOS-9
3953 PUT (XC,YC),CUR '----- Put image CUR at XC,YC
3954 GOTO 3879
3960 ' Check values
3970 IF XPOS<XVI+15 THEN XPOS=XVI+15:BEEP
3971 IF XPOS>X1VI-15 THEN XPOS=X1VI-15:BEEP
3980 IF YPOS<YVI+9 THEN YPOS=YVI+9:BEEP
3981 IF YPOS>Y1VI-8 THEN YPOS=Y1VI-8:BEEP
3990 RETURN
4000 IF XVI<0 THEN XVI=0 ELSE IF XVI>719 THEN XVI=719
4010 IF YVI<0 THEN YVI=0 ELSE IF YVI>299 THEN YVI=299
4020 RETURN
4030 ' Draw and get cursor
4040 DEFINT C:DIM CTEMP(110),CUR(110)
4041 GET (0,0)-(29,17),CTEMP
4042 LINE (0,0)-(29,17),0,BF '----- Define the cursor
4043 LINE (0,9)-(8,9),6:LINE (21,9)-(29,9),6 '----- lines (x,y) to (x1,y1)
4044 LINE (15,0)-(15,4),7:LINE (15,13)-(15,17),7
4045 PSET(15,9),7
4046 GET (0,0)-(29,17),CUR '----- Store image in array CUR
4047 LINE (0,0)-(29,17),0,BF
4048 PUT(0,0),CTEMP
4049 ERASE CTEMP '----- Erase the array CTEMP
4050 RETURN
4820 ' Arowinit.SUB Steve Enns Dec.18 1983
4830 '
4840 ' Initializes arrow keys for trapping
4850 ' Returns LQ$,RQ$,UQ$,DQ$,HQ$ as the arrow keys on return
4860 ' Returns SLQ$,SRQ$,SUQ$,SDQ$,SHQ$ as the shifted arrow keys
4870 '
4872 LQ$=CHR$(0)+"K":RQ$=CHR$(0)+"M"
4874 UQ$=CHR$(0)+"H":DQ$=CHR$(0)+"P"
4876 HQ$=CHR$(0)+"G":SRQ$=CHR$(0)+"è"
4878 SLQ$=CHR$(0)+"ï":SUQ$=CHR$(0)+"ê"
4879 SDQ$=CHR$(0)+"ë":SHQ$=CHR$(0)+"å"
4880 RETURN
9810 ' Baskeys.SUB Steve Enns Dec. 30 1983
9812 '
9815 ' Initializes keys to BASIC defaults
9820 '
9821 KEY 1,CHR$(27)+"LIST "
9822 KEY 2,CHR$(27)+"RUN"+CHR$(13)
9823 KEY 3,"LOAD"+CHR$(34)
9824 KEY 4,"SAVE"+CHR$(34)
9825 KEY 5,CHR$(27)+"FILES"+CHR$(13)
9826 KEY 6,CHR$(27)+"CONT"+CHR$(13)
9827 KEY 7,".SUB"
9828 KEY 8,".UTL"
9829 KEY 9,CHR$(27)+"COLOR 3,0,0,0"+CHR$(13)
9830 KEY 10,CHR$(27)+"PALETTE"+CHR$(13)
9840 RETURN
16850 ' BSpline.SUB Steve Enns Dec.20 1984
16852 ' From Fund. of Int CG. p.521
16854 '
16856 ' Calculates cubic parametric free-form splines
16858 ' XBS23=1 for 3d else 2d
16860 ' XBSDR=0 if the curve is to be drawn
16862 ' XC(),YC(),[ ZC() ] are the control points
16864 ' XNC is the index of first control point
16866 ' XNB is the number of control points to be used
16868 ' XNP is the index for the first spline point
16870 ' NBS is the step size
16872 ' QBS is the color if drawn
16874 ' Returns X(),Y(),[ Z() ] as the points
16876 ' Returns XNS as the index of the last spline point
16878 '
16880 IS=XNP:XXS=XNC+XNB-3:NSA=1/6:NSB=2/3
16882 IF XBS23 THEN 16904
16884 FOR IIS=XNC+1 TO XXS
16886 FOR T=0 TO 1 STEP NBS
16888 T1=T/2:T2=T*T:T2A=T2/2:T3=T2*T:T3A=T3/2
16890 NC1=-NSA*T3+T2A-T1+NSA:NC2=T3A-T2+NSB:NC3=-T3A+T2A+T1+NSA:NC4=NSA*T3
16892 X(IS)=NC1*XC(IIS-1)+NC2*XC(IIS)+NC3*XC(IIS+1)+NC4*XC(IIS+2)
16894 Y(IS)=NC1*YC(IIS-1)+NC2*YC(IIS)+NC3*YC(IIS+1)+NC4*YC(IIS+2)
16896 IS=IS+1
16898 NEXT
16900 NEXT
16902 GOTO 16924
16904 FOR IIS=XNC+1 TO XXS
16906 FOR T=0 TO 1 STEP NBS
16908 T1=.5*T:T2=T*T:T2A=.5*T2:T3=T2*T:T3A=T3/2
16910 NC1=-NSA*T3+T2A-T1+NSA:NC2=T3A-T2+NSB:NC3=-T3A+T2A+T1+NSA:NC4=NSA*T3
16912 X(IS)=NC1*XC(IIS-1)+NC2*XC(IIS)+NC3*XC(IIS+1)+NC4*XC(IIS+2)
16914 Y(IS)=NC1*YC(IIS-1)+NC2*YC(IIS)+NC3*YC(IIS+1)+NC4*YC(IIS+2)
16916 Z(IS)=NC1*ZC(IIS-1)+NC2*ZC(IIS)+NC3*ZC(IIS+1)+NC4*ZC(IIS+2)
16918 IS=IS+1
16920 NEXT
16922 NEXT
16924 XNS=IS
16926 IF XBSDR THEN 16936
16928 PSET(X(XNP),Y(XNP)),QBS '----- Set pixel, x,y color QBS
16930 FOR II=XNP TO XNP+XNS-1
16932 LINE -(X(II),Y(II)),QBS '----- Line from last X,Y to
16934 NEXT 'X1,Y1 color QBS
16936 RETURN
16960 ' Bezier2.SUB Steve Enns Dec.22 1984
16962 ' From Fund. of Int CG. p.519
16964 '
16966 ' Calculates cubic parametric free-form Bezier curves
16968 ' XBS23=1 for 3d else 2d
16970 ' XBZDR=0 is the curve is to be drawn (2d only)
16972 ' XC(),YC(),[ ZC() ] are the hull points (4 per curve)
16974 ' XNC is the index of first control point
16976 ' XNB is the number of control points to be used
16978 ' XNP is the index for the first curve point
16980 ' NBS is the step size (default provided)
16982 ' QBZ is the color if drawn
16984 ' Returns X(),Y(),[ Z() ] as the points
16986 ' Returns XNS as the index of the last curve point
16988 '
16990 IS=XNP:XXS=XNC+XNB-1
16992 IF NBS=0 THEN NBS=.1
16994 IF XBS23 THEN 17016
16996 FOR IIS=XNC TO XXS STEP 4
16998 FOR T=0 TO 1+NBS STEP NBS
17000 T2=T*T:T3=T2*T
17002 NC1=1-3*T+3*T2-T3:NC2=3*T3-6*T2+3*T:NC3=3*T2-3*T3:NC4=T3
17004 X(IS)=NC1*XC(IIS)+NC2*XC(IIS+1)+NC3*XC(IIS+2)+NC4*XC(IIS+3)
17006 Y(IS)=NC1*YC(IIS)+NC2*YC(IIS+1)+NC3*YC(IIS+2)+NC4*YC(IIS+3)
17008 IS=IS+1
17010 NEXT
17012 NEXT
17014 GOTO 17036
17016 FOR IIS=XNC TO XXS STEP 4
17018 FOR T=0 TO 1+NBS STEP NBS
17020 T2=T*T:T3=T2*T
17022 NC1=1-3*T+3*T2-T3:NC2=3*T3-6*T2+3*T:NC3=3*T2-3*T3:NC4=T3
17024 X(IS)=NC1*XC(IIS)+NC2*XC(IIS+1)+NC3*XC(IIS+2)+NC4*XC(IIS+3)
17026 Y(IS)=NC1*YC(IIS)+NC2*YC(IIS+1)+NC3*YC(IIS+2)+NC4*YC(IIS+3)
17028 Z(IS)=NC1*ZC(IIS)+NC2*ZC(IIS+1)+NC3*ZC(IIS+2)+NC4*ZC(IIS+3)
17030 IS=IS+1
17032 NEXT
17034 NEXT
17036 XNS=IS-1
17038 IF XBZDR THEN 17048
17040 PSET(X(XNP),Y(XNP)),QBZ '----- Pixel at x,y color QBZ
17042 FOR II=XNP TO XNP+XNS
17044 LINE -(X(II),Y(II)),QBZ '----- Line from last X,Y to
17046 NEXT 'X1,Y1 color QBZ
17048 RETURN
'----- Line from last X,